from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SpecificationOption, SPUSpecification
from meiduo_admin.serializers.options import OptionSerialzier, OptionSpecificationSerializer
from meiduo_admin.serializers.specs import SpecSerializer
from meiduo_admin.utils import PageNum


class OptionsView(ModelViewSet):
    """
            规格选项表的增删改查
    """


    serializer_class = OptionSerialzier

    queryset = SpecificationOption.objects.all()

    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    # def simple(self,request):
    #     specs = SPUSpecification.objects.all()
    #     ser = SpecSerializer(specs, many=True)
    #     return Response(ser.data)
class OptionSimple(ListAPIView):
    """
        获取规格信息
    """
    serializer_class = OptionSpecificationSerializer
    queryset = SPUSpecification.objects.all()
